<html>
<head>
    <meta charset="utf-8" />
    <title>Cef Tests</title>
    <script language="JavaScript">
        function sendMacMessage() {
            //var mac = nativeAPI.call('mac');
            //console.log('mac:' + mac);
            let name = "打开C++pdf浏览器";
            let params = {
                type: "PDFViewer",
                module: "macroData",
                fileId: "55663211",
            };
            if (typeof params === "object") {
                params = JSON.stringify(params);
                console.log("params:",params);
            }
            var jsonObj = {
                request: `["req_openpage", [{"args":"${name}","params":${params}}]]`,
                onSuccess: function (response) { console.log(response); },
                onFailure: function (error_code, error_message) { console.log(error_message); }
            };

            console.log("jsonObj:", JSON.stringify(jsonObj));
            cefQuery(jsonObj);
        }
        function sendGetMessage() {
            nativeAPI.call('get', { url: 'http://192.168.10.200:9667/data/getDir' }
            ).then(data => {
                console.log("hello get:", data);
            });
        }
        function sendPostMessage() {
            nativeAPI.call('post', {
                url: 'http://dss.nanhui.idbhost.com/prod/ss/data/sync/user/login', param: {
                    username: 'haha',
                    pass: 'aaa'
                }
            }).then(data => {
                console.log("hello post:", data);
            });
        }
        function sendMaxMessage() {
            nativeAPI.call('setZoomMax');
        }
        function sendUploadMessage() {
            nativeAPI.call('upload', {url: 'http://192.168.10.200:9667/data/uploadFile/%E9%BB%98%E8%AE%A4%E6%95%B0%E6%8D%AE%E6%BA%90'}
            ).then(data => {
                console.log("hello upload:", data);
            });
        }

        // 写一个JS函数，让C++可以通过调用这个函数控制网页
        ((obj) => {
            obj.register('called', (param)=>{
                document.getElementById("result").value = "收到来自C++的消息:" + JSON.stringify(param);
            })
        })(nativeAPI)
    </script>
</head>

<body bgcolor="white">
    <h3>Cef3.2623 C++与JS交互功能测试页面</h3>

    <fieldset style="margin-top:20px;border-color:#E2DED6;border-width:1px;border-style:Solid;">
        <legend style="color:#333333;font-size:0.8em;font-weight:bold;">
            JS调用C++测试
        </legend>

        <div style="margin-left:10px">
            发送给C++的文本: <input type="text" id="message" value="你好C++！">
            <br />
            <input type="button" onclick="sendMacMessage();" value="get mac">
            <input type="button" onclick="sendGetMessage();" value="http get">
            <input type="button" onclick="sendPostMessage();" value="http post">
            <input type="button" onclick="sendMaxMessage();" value="zoom max">
            <input type="button" onclick="sendUploadMessage();" value="file upload">
        </div>
    </fieldset>

    <fieldset style="margin-top:20px;border-color:#E2DED6;border-width:1px;border-style:Solid;">
        <legend style="color:#333333;font-size:0.8em;font-weight:bold;">
            C++调用JS测试
        </legend>

        <div style="margin-left:10px">
            收到C++发来的的文本：
            <br /><textarea rows="2" cols="40" id="result"></textarea>
        </div>
    </fieldset>
</body>
</html>